<!DOCTYPE html>
<html lang="en">
<head xmlns:th="http://www.thymeleaf.org">
    <meta charset="UTF-8">
    <title>用户登录页面</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery-3.6.0.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <style>
        b{
            font-weight: bolder;
            color: #fd6363;
        }
    </style>
    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">
</head>

<!--登陆页面-->
<body>
    <div class="container-fluid" style="padding: 100px 440px 10px;">
        <div class="panel panel-default">
            <div class="panel-body">
                <h2 align="center">登录成绩管理系统</h2>
                <form>
                    <div class="form-group">
                        <label for="username">用户名：</label>
                        <input type="text" class="form-control" id="username" name="username" placeholder="用户名">
                    </div>
                    <div class="form-group">
                        <label for="password">密码：</label>
                        <input type="number" class="form-control" id="password" name="password" placeholder="密码"
                               style="-webkit-text-security:disc"/>
                    </div>
                    <label class="radio-inline">
                        <input type="radio" name="inlineRadioOptions" id="teacher"  value="2"> 教师
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="inlineRadioOptions" id="student"  value="1"> 学生
                    </label>
                    <div class="form-group">
                        <div class="col-sm-offset-0 ">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox"> 记住密码
                                </label>
                            </div>
                        </div>
                    </div>
                    <div style="margin-left: 250px;">
                        <button type="button" class="btn btn-primary btn-lg"  onclick="login();">登录</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="/js/bootstrap.min.js"></script>
    <script src="/plugins/bootstraptable/bootstrap-table.min.js"></script>
    <script src="/plugins/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>

    <script type="text/javascript">
    function login() {
        var username = $("#username").val();
        var password = $("#password").val();
        var radioVal = $('input:radio:checked').val();//获取被选中Radio的Value值
        $.ajax({
            url: "/webapi/login/user",
            data: {
                method: "put",
                username: username,
                password: password,
                radioVal: radioVal,
            },
        }).done(function (rs) {
            //成功
            // 判断跳转页面
            if (rs == 1) {//学生登录
                window.location.href = "/sc/ssclist";
                //学生登录后只能查看自己的信息
                // $.ajax({
                //     url: '/webapi/student/self',
                //     data: {
                //         method: "put",
                //         username2: username,
                //         password2: password,
                //     },
                // }).done(function (rs){
                //     if(rs==1){
                //         window.location.href = "/student/slist";
                //     }
                // })
            }
            else if (rs == 2) {//教师登录
                window.location.href = "/teacher/tlist";
                //window.location.href="/student/list";
                //window.location.href="/sc/sclist";
            }
            //失败
            else if (rs == -1) {
                alert("用户名或密码错误！");
            }
            else
            {
                alert("请选择用户类型！");
            }
        });

        $.ajax({
            url: '/webapi/student/self',
            data: {
                method: "put",
                username: username,
                password: password,
                radioVal: radioVal,
            },
        });
    }

    </script>

</body>
</html>